1 /* 2 Copyright: Marcelo S. N. Mancini (Hipreme|MrcSnm), 2018 - 2021 3 License: [https://creativecommons.org/licenses/by/4.0/|CC BY-4.0 License]. 4 Authors: Marcelo S. N. Mancini 5 6 Copyright Marcelo S. N. Mancini 2018 - 2021. 7 Distributed under the CC BY-4.0 License. 8 (See accompanying file LICENSE.txt or copy at 9 https://creativecommons.org/licenses/by/4.0/ 10 */ 11 12 module hip.api.input.button; 13 14 enum HipButtonType : ubyte 15 { 16 down = 0, 17 up = 1 18 } 19 20 enum AutoRemove : bool 21 { 22 no = false, 23 yes = true 24 } 25 alias HipInputAction = void delegate(const(AHipButtonMetadata) meta); 26 alias HipTouchMoveAction = void delegate(int x, int y); 27 alias HipScrollAction = void delegate(float[3]); 28 29 /** 30 * Handler for any kind of button 31 */ 32 struct HipButton 33 { 34 ushort id; 35 HipButtonType type; 36 AutoRemove isAutoRemove = AutoRemove.no; 37 HipInputAction action; 38 39 alias id this; 40 } 41 42 struct TouchMoveListener 43 { 44 HipTouchMoveAction action; 45 AutoRemove isAutoRemove = AutoRemove.no; 46 } 47 48 struct ScrollListener 49 { 50 HipScrollAction action; 51 AutoRemove isAutoRemove = AutoRemove.no; 52 } 53 54 abstract class AHipButtonMetadata 55 { 56 int id; 57 this(int id){this.id = id;} 58 public abstract float getDownTimeDuration() const; 59 public abstract float getLastDownTimeDuration() const; 60 public abstract float getUpTimeDuration() const; 61 public abstract float getLastUpTimeDuration() const; 62 public abstract bool isPressed() const; 63 ///Useful for looking justPressed and justRelease 64 public abstract bool isNewState() const; 65 ///User API is not expected to call that function. It is used for controlling the input flow 66 public abstract void setPressed(bool press); 67 public final bool isJustReleased() const {return !isPressed && isNewState;} 68 public final bool isJustPressed()const {return isPressed && isNewState;} 69 }